//引入axios
import axios from 'axios';
import  NProgress from 'nprogress';
import 'nprogress/nprogress.css';

//创建axios实例
const mockAjax = axios.create({
    baseURL:'/mock',
    timeout:1000
})
//设置请求拦截
mockAjax.interceptors.request.use(config => {

    //设置进度条
    NProgress.start();
    return config;

})
//设置响应拦截
mockAjax.interceptors.response.use(
    response=>{
        //进度条结束
        NProgress.done();
        //请求成功响应数据
        return response.data;
    },
    error => {
        NProgress.done();
        return Promise.reject(new Error(error.message))
    }
)
export default mockAjax;